<template>
  <div class="app-container">
    <el-row>
      <el-col :span="24">
        <div class="table-page-search-wrapper">
          <el-form :inline="true" label-width="100px">
            <el-row :gutter="18">
              <el-col :md="8" :sm="24">
                <el-form-item label="物料名称">
                  <el-input
                    v-model="queryParam.goodsName"
                    placeholder=""
                    clearable
                    @keyup.enter.native="onSearch"
                    @clear="onSearch"
                  />
                </el-form-item>
              </el-col>
              <el-col :md="8" :sm="24">
                <el-form-item label="商品编码">
                  <el-input
                    v-model="queryParam.goodsCode"
                    placeholder=""
                    clearable
                    @keyup.enter.native="onSearch"
                    @clear="onSearch"
                  />
                </el-form-item>
              </el-col>
              <el-col :md="8" :sm="24">
                <span class="table-page-search-submitButtons">
                  <el-button
                    v-waves
                    type="primary"
                    icon="el-icon-search"
                    @click="onSearch"
                  >
                    查询
                  </el-button>
                  <el-button type="info" icon="el-icon-refresh" @click="reset">
                    重置
                  </el-button>
                  <el-button type="primary" icon="" @click="$refs.form.open()">
                    新建商品
                  </el-button>
                </span>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <el-table
          v-loading="loadingData"
          :data="list"
          element-loading-text="Loading"
          fit
          highlight-current-row
          @row-click="singleElection"
        >
          <el-table-column label="" width="65">
            <template slot-scope="{$index}">
              <el-radio v-model="templateSelection" class="radio" :label="$index">&nbsp;</el-radio>
            </template>
          </el-table-column>
          <el-table-column type="index" label="序号" />
          <el-table-column align="center" label="商品编码">
            <template slot-scope="scope">
              <span>
                {{ scope.row.goodsCode }}
              </span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="物料名称">
            <template slot-scope="scope">
              <span>
                {{ scope.row.goodsName }}
              </span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="规格">
            <template slot-scope="scope">
              <span>
                {{ scope.row.specifications }}
              </span>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="pagination.total > 0"
          :total="pagination.total"
          :page.sync="pagination.current"
          :limit.sync="pagination.pageSize"
          :style="{ textAlign: 'right' }"
          @pagination="handlePaginationChanged"
        />
      </el-col>
    </el-row>

    <diboot-form ref="form" @complete="getList" />
  </div>
</template>

<script>
import list from '@/components/diboot/mixins/list'
import waves from '@/directive/waves'
import dibootForm from './form'

export default {
  name: 'GoodsList',
  directives: { waves },
  components: {
    dibootForm
  },
  mixins: [list],
  data() {
    return {
      baseApi: '/goods',
      templateSelection: '',
      templateRadio: null,
      getListFromMixin: true
    }
  },
  methods: {
    singleElection(row) {
      this.templateSelection = this.list.indexOf(row)
      this.templateRadio = row
    }
  }
}
</script>
<style lang="scss" scoped>
.qr-list {
  display: flex;
  flex-wrap: wrap;
}
</style>
